/**
 * SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
 * SPDX-License-Identifier: Mulan PSL v2
 */

<!-- 新增服务镜像弹窗 -->

<template>
    <sf-form-item class="flex">
        <sf-fieldlabel>
            <lang>参数描述</lang>
        </sf-fieldlabel>
        <div class="algorithm-params__wrap">
            <div class="algorithm-params-list">
                <div v-for="(item,index) in algorithmParamsList"
                     :key="index"
                     class="filter-item">
                    <sf-textfield
                        ref="fieldName"
                        v-model="item.paramName"
                        :default-width="130"
                        :utf8-length="false"
                        :blur-trim="true"
                        :placeholder="_('参数名称')" />
                    <sf-textfield
                        ref="fieldName"
                        v-model="item.value"
                        :default-width="100"
                        :utf8-length="false"
                        :blur-trim="true"
                        :placeholder="_('默认值')" />
                    <sf-textfield
                        ref="fieldName"
                        v-model="item.description"
                        :default-width="215"
                        :utf8-length="false"
                        :blur-trim="true"
                        :placeholder="_('描述（选填）')" />
                    <span v-if="algorithmParamsList.length > 0"
                          class="icon iconfont iconqingkong remove"
                          @click="_removeListItem(index)"></span>
                </div>
            </div>
            <div class="add-filter"
                 @click="_addListItem">
                <span class="icon iconfont iconsip-add"></span>
            </div>
        </div>
    </sf-form-item>
</template>
<style lang="less">
.algorithm-params__wrap{
    .algorithm-params-list{
        max-height: 140px;
        overflow: auto;
        .remove{
            cursor: pointer;
            &:hover{
                color: #204ed9;
            }
        }
        .filter-item{
            margin-bottom: 10px;
            margin-left: 4px;
        }
        .sfv-select{
            margin-right: 6px;
        }
    }
    .add-filter{
        width: 452px;
        margin-left: 4px;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 30px;
        border: 1px dashed rgba(73,80,96,0.3);
        border-radius: 2px;
        cursor: pointer;
        .iconsip-add{
            color: inherit;
        }
    }
}
</style>

<script>

const DEFAULT_WIDTH = 336;
import parseJson from 'src/util/parse_json.ts';

export default {
    computed: {
        defaultWidth () {
            return DEFAULT_WIDTH;
        }

    },
    data () {
        return {
            algorithmParamsList:[]
        };
    },

    methods: {
        _removeListItem (index) {
            this.algorithmParamsList.splice(index, 1);
        },
        _addListItem () {
            this.algorithmParamsList.push({
                paramName:'',
                value:'',
                description:''
            });
        },
        setJsonValue (data) {
            this.algorithmParamsList = parseJson(data.paramsDescription);
        },
        getJsonValue () {
            let algorithmParamsList = JSON.stringify(this.algorithmParamsList);
            return algorithmParamsList;
        },
        reset () {
            this.$nextTick().then(()=>{
                this.algorithmParamsList = [];
            });

        }

    }
};
</script>
